//Estimate the expected value of the random variable K.
#include <stdio.h>
#include "uniform.c"

#define SIZE 100000 //generate 100000 random variate K

double uniform(double *);

int main() {

  int k,j;
  double seed;
  double x=0;
  double sum=0;
  double mean,y;

  for (j=0;j<SIZE;j++){
	  seed = 1234567+j*100000; //set the seed differently
	  x=0;
	  k=0;
	  while (x<=1){
		  y = uniform(&seed); //generate an uniform variate y
		  x = x + y;  //compute x
		  k++;
	  }
	  sum=sum+k;
  }
  mean=sum/SIZE;
  printf("The expected value of K is %g\n",mean);
}
      
      
      
    

